/*
 * Copyright (c) 2024-2025 LTC-CN. All rights reserved.
 * <p>
 * This file is part of the ltc-cn-springboot project.
 * <p>
 * ltc-cn-springboot is distributed under the terms of the MIT License.
 * For details, see the accompanying LICENSE file or visit:
 * <a href="https://www.ltc-cn.top/projects">...</a>
 */

package top.ltc_cn.springboot_tools.tools.passwordUtils;
//
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;
import org.springframework.stereotype.Component;

@Component
public class Argon2Utils {

    private Argon2Utils() {} // 防止实例化

    private static final Argon2 argon2 = Argon2Factory.create();

    // 使用 Argon2 哈希密码
    public static String hashPassword(String password) {
        return argon2.hash(2, 65536, 1, password.toCharArray());
    }

    /**
     * 验证密码
     * @param password 待验证的密码
     * @param storedHash 已存储的哈希值
     * @return 验证结果
     */
    public static boolean verifyPassword(String password, String storedHash) {
        return argon2.verify(storedHash, password.toCharArray());
    }
}